﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Final
{
    public partial class RegisterForm : Form
    {
        public RegisterForm()
        {
            InitializeComponent();
        }


        //注册界面返回按钮
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        //注册界面注册按钮
        private void button1_Click(object sender, EventArgs e)
        {
            var user = ReName.Text;
            var pwd = RePwd.Text;
            var pwd2 = pwd==RePwd2.Text;
            var sql = string.Format("select * from Users where UserName='{0}' and UserPwd='{1}'", user, pwd);
            var sql1 = string.Format("select * from Users where UserName='{0}' and UserPwd='{1}'", user, pwd);
            var d = DBhelp.GetDataTable(sql1);
            if (d.Rows.Count==1)
            {
                MessageBox.Show("该用户已存在");
            }
            else
            {

                if (user != "" || pwd != "")
                {
                    string UserSql = string.Format("select * from Users where UserName='{0}'", user);
                    var re = DBhelp.LoginRegister(UserSql);
                    if (re == false)
                    {
                        if (pwd2)
                        {
                            var Sql = string.Format("insert into Users (UserName,UserPwd) values ('{0}',{1})", user, pwd);
                            DBhelp.GetDataTable(Sql);
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("两次输入的密码不对，请重新确认");
                        }
                    }
                    else
                    {
                        MessageBox.Show("你输入的用户名已存在");

                    }
                }
                else
                {
                    MessageBox.Show("用户名或密码为空");
                }

            }
            
        }

        private void RegisterForm_Load(object sender, EventArgs e)
        {

        }
    }
}
